<?php 
define("CCTRL", "subscriber");
define("CCTRLNAME", "subscriber");
define("TOKEN", "bd1daf9402d571eb9cc38451c49728c0");
session_start();

class subscriber extends CI_Controller  {

        /**
        * Index Page for this controller.
        *
        * Maps to the following URL
        * 		http://example.com/index.php/welcome
        *	- or -  
        * 		http://example.com/index.php/welcome/index
        *	- or -
        * Since this controller is set as the default controller in 
        * config/routes.php, it's displayed at http://example.com/
        *
        * So any other public methods not prefixed with an underscore will
        * map to /index.php/welcome/<method_name>
        * @see http://codeigniter.com/user_guide/general/urls.html
        */
       private $_configs = null;
       function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->library('smarty3');
            $this->load->model('colmod/subscriber_colmod');
            $this->load->model('APanel/customer_model');
            $this->load->model('APanel/type_model');
            include APPPATH . 'libraries/defu.php';
            if(!isset($_SESSION["ADP"][CCTRL]["display"]))$_SESSION["ADP"][CCTRL]["display"]=0;
            if(!isset($_SESSION["ADP"][CCTRL]["pageSize"]))$_SESSION["ADP"][CCTRL]["pageSize"]=100;
            
            $this->colModel=new subscriber_colmod();
            $this->smarty=new CI_Smarty3();$this->smarty->error_reporting = E_ALL & ~E_NOTICE;
            $this->customer_model=new customer_model();
            $this->type_model=new type_model();
        }
        public function index()
	{
            //unset($_SESSION["ADP"][CCTRL."-JQX"]["colModel"]);
            if(!checkAuthority(CCTRLNAME)){
                $this->smarty
                        ->assign('_SESSION', $_SESSION)
                        ->display("sys/04_access_denied");
                return;
            }
            $tmp=$this->type_model->getByType("Group");
            foreach ($tmp as $v){
                $Data["groups"][]=$v->Name;
            }
            if(isset($_SESSION["ADP"][CCTRL."-JQX"]["colModel"]))
                $colModel=$_SESSION["ADP"][CCTRL."-JQX"]["colModel"];
            else{
                $this->colModel=new subscriber_colmod($Data["groups"]);
                $colModel=$this->colModel->get();
                $_SESSION["ADP"][CCTRL."-JQX"]["colModel"]=$colModel;
            }
            $Data["colModel"]=$colModel;
            $Data["display"]=$_SESSION["ADP"][CCTRL]["display"];
            $Data["pageSize"]=$_SESSION["ADP"][CCTRL]["pageSize"];
            $this->smarty
                    ->assign('_SESSION', $_SESSION)
                    ->assign('Data', $Data)
                    ->display("APanel/".CCTRL."/".CCTRL);
	}
        
        function jqgrid_data(){
            $colModel=$this->colModel->get();
            //$Categorys=$this->category_model->gets();
            //$Regions=$this->region_model->getByParent();
            $orders=array();
            $result['total_rows']=0;
            //if($this->checkauthority()>=0){
                $result=$this->customer_model->bindingMail();
                $rows=$result['rows'];
                // get data and store in a json array
                foreach ($rows as $row) {
                    $cel=array();
                    foreach ($colModel as $col){
                        $f=$col["datafield"];
                        $cel[$f]=$row->$f;
                    }
                    $orders[] = $cel;
                }
            
            $data[] = array(
                'TotalRows' => $result['total_rows'],
                'Rows' => $orders
            );
            echo json_encode($data);
        }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */